package com.ljwy.gun;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * dialog封装
 */

public class BuilderDialog {

    private Dialog dialog;
    private Window window;

    public BuilderDialog(Context context) {
        super();
        this.dialog = new Dialog(context, R.style.dialog);
        dialog.setOnDismissListener(dialog -> {
            if (selectSexDiaLogDismissLister != null) {
                selectSexDiaLogDismissLister.onDiaLogDismss();
            }
        });
    }

    /**
     * 设置从哪里弹出
     */
    public BuilderDialog setGrvier(int grvier) {
        if (window == null) {
            window = dialog.getWindow();
        }
        window.setGravity(grvier);
        return this;
    }

    /**
     * 设置视图
     */
    public BuilderDialog setContentView(View view) {
        dialog.setContentView(view);
        return this;
    }

    /**
     * 设置是否全屏
     */
    public BuilderDialog setFullScreen() {
        if (window == null) {
            window = dialog.getWindow();
        }
        WindowManager.LayoutParams layouParams = window.getAttributes();
        layouParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        return this;
    }

    /**
     * 显示Dialog
     */
    public BuilderDialog setShow() {
        dialog.show();
        return this;
    }

    /**
     * 隐藏Dialog
     */
    public BuilderDialog setDismiss() {
        dialog.dismiss();
        return this;
    }

    /**
     * Dialog的动画
     */
    public BuilderDialog setAniMo(int anim) {
        if (window == null) {
            window = dialog.getWindow();
        }
        window.setWindowAnimations(anim);
        return this;
    }

    /**
     * 点击外部不消失
     *
     * @return
     */
    public BuilderDialog setOutSideDismiss() {
        dialog.setCancelable(false);
        return this;
    }

    public interface DismissLisenter {
        void onDiaLogDismss();
    }

    private DismissLisenter selectSexDiaLogDismissLister;

    public void setDiaLogDismissLister(DismissLisenter selectSexDiaLogDismissLister) {
        this.selectSexDiaLogDismissLister = selectSexDiaLogDismissLister;
    }


}
